/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmMain.java
 *
 * Created on Oct 24, 2011, 4:34:15 PM
 */
package ttfsserver;

import static java.awt.SystemTray.getSystemTray;

import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.InetAddress;
import java.net.URL;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.Timer;
import javax.swing.UIManager;
import myutil.Utility;
import pojo.POJOFileClient;
import pojo.POJOInfoClient;
import pojo.POJOInfoSharedFile;
import pojo.POJOMyInfo;

/**
 *
 * @author Tidus Le
 */
public class frmMain extends javax.swing.JFrame
{
    public static boolean changeInfo=true;
    public static boolean changeFile=true;
    
    //info
    public static POJOMyInfo myinfo=new POJOMyInfo();
    
    public static ArrayList<POJOInfoClient> arrInfoClients=new ArrayList<POJOInfoClient>();
    public static ArrayList<POJOInfoSharedFile> arrInfoSharedFiles=new ArrayList<POJOInfoSharedFile>();
    public static ArrayList<POJOFileClient> arrFileClient=new ArrayList<POJOFileClient>();
    /** Creates new form frmMain */
    public frmMain() {
        initComponents();
        
        //Tray icon
        trayIcon();
        
        //Onload
        clsXMLInfoClient.read(arrInfoClients);
        clsXMLInfoSharedFile.read(arrInfoSharedFiles);
        clsXMLFileClient.read(arrFileClient);
        clsXMLMyInfo.readMyInfo(myinfo);
        loadClientsList();
        
        //start server threading
        clsServerThread server=new clsServerThread(Integer.parseInt(myinfo.getPort()));
        server.start();
        
        //timer to listener changing of data
        Timer timer=new Timer(200, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if(changeInfo==true)
                {
                    changeInfo=false;
                    try
                    {
                        jLabel2.setToolTipText(InetAddress.getLocalHost().getHostAddress());
                    }catch(Exception ex)
                    {
                    }
                    loadClientsList();
                    clsXMLInfoClient.write(arrInfoClients);
                    clsXMLMyInfo.writeMyInfo(myinfo);
                }
                
                if(changeFile==true)
                {
                    changeFile=false;
                    //loadClientsList();
                    clsXMLInfoSharedFile.write(arrInfoSharedFiles);
                    clsXMLFileClient.write(arrFileClient);
                    
                    loadSharedFileList();
                }
            }
        });
        timer.start();
    }
    
    /**
     * Thêm tray icon
     */
    private void trayIcon()
    {
        URL resource = getClass().getResource("/myutil/icon.png");
        Image image = Toolkit.getDefaultToolkit().getImage(resource);
        setIconImage(image);
        if (SystemTray.isSupported()) {
            final TrayIcon icon = new TrayIcon(image);
            icon.setToolTip("Tata File Sharing - Server");
            icon.setImageAutoSize(true);
            icon.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    frmMain.this.setVisible(true);
                    frmMain.this.setExtendedState(frmMain.NORMAL);
                    getSystemTray().remove(icon);
                }

            });
            addWindowListener(new WindowAdapter() {

                @Override
                public void windowIconified(WindowEvent e) {
                    frmMain.this.setVisible(false);
                    try {
                        getSystemTray().add(icon);
                    } catch (AWTException e1) {
                        e1.printStackTrace();
                    }
                }

            });
        }
    }
    
    /**
     * Hiển thị danh sách các client ra listbox
     */
    private void loadClientsList()
    {
        DefaultListModel listModel=new DefaultListModel();
        DefaultListModel listModelOnline=new DefaultListModel();
        for(POJOInfoClient ic:arrInfoClients)
        {
            listModel.addElement(ic.getId());
            if(ic.getStatus().equals("on")==true)
                listModelOnline.addElement(ic.getId());
        }
        
        listClients.setModel(listModel);
        listOnline.setModel(listModelOnline);
    }
    
    /**
     * Hiển thị danh sách các file đang được chia sẻ
     */
    private void loadSharedFileList()
    {
        DefaultListModel listModel=new DefaultListModel();
        for(POJOInfoSharedFile sf:arrInfoSharedFiles)
        {
            listModel.addElement(sf.getName());
        }
        
        listSharedFile.setModel(listModel);
    }
    
    /**
     * Hiện ra danh sách các client đang chia sẽ file này
     */
    private void loadFileClientList(String fid)
    {
        DefaultListModel listModel=new DefaultListModel();
        for(POJOFileClient fc:arrFileClient)
        {
            if(fc.getFid().equals(fid)==true)
                listModel.addElement(fc.getCid());
        }
        
        listFileClient.setModel(listModel);
    }
    
    /**
     * Hiện thị thông tin của client
     */
    private void loadInfoClient(String id)
    {
        for(POJOInfoClient ic:arrInfoClients)
        {
            if(ic.getId().equals(id)==true)
            {
                this.lblID.setText(ic.getId());
                this.lblIP.setText(ic.getIp());
                this.lblName.setText(ic.getName());
                this.lblPort.setText(ic.getPort());
                if(ic.getStatus().equals("on"))
                    this.lblStatus.setText("Online");
                else
                    this.lblStatus.setText("Offline");

                break;
            }
        }
    }
    
    /**
     * Hiện ra thông tin của file được chia sẻ
     */
    private void loadInfoFile(String id)
    {
        for(POJOInfoSharedFile sf:arrInfoSharedFiles)
        {
            if(sf.getFid().equals(id)==true)
            {
                this.lblFileId.setText(sf.getFid());
                this.lblFileName.setText(sf.getName());
                this.lblFileSize.setText(Utility.getSize(sf.getSize()));
            }
        }
        
        //load client
        loadFileClientList(id);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listClients = new javax.swing.JList();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblID = new javax.swing.JLabel();
        lblName = new javax.swing.JLabel();
        lblIP = new javax.swing.JLabel();
        lblPort = new javax.swing.JLabel();
        lblStatus = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listOnline = new javax.swing.JList();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        listSharedFile = new javax.swing.JList();
        jPanel6 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lblFileName = new javax.swing.JLabel();
        lblFileId = new javax.swing.JLabel();
        lblFileSize = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        listFileClient = new javax.swing.JList();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        mnuExit = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        mnuConfig = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        mnuAbout = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Server - Tata File Sharing");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Clients đã định danh", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        listClients.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listClients.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listClients.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listClientsValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(listClients);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin client", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel1.setText("ID:");

        jLabel2.setText("IP:");

        jLabel3.setText("Port:");

        jLabel4.setText("Name:");

        jLabel5.setText("Status:");

        lblID.setForeground(new java.awt.Color(102, 0, 255));

        lblName.setForeground(new java.awt.Color(102, 0, 255));

        lblIP.setForeground(new java.awt.Color(102, 0, 255));

        lblPort.setForeground(new java.awt.Color(102, 0, 255));

        lblStatus.setForeground(new java.awt.Color(102, 0, 255));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblID, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblName, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblIP, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblPort, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(lblName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblIP))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(lblPort))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(lblStatus)))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Đang online", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        listOnline.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listOnline.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listOnlineValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(listOnline);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
        );

        jPanel4.setBackground(new java.awt.Color(245, 255, 245));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Những file đang được chia sẻ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 51, 255))); // NOI18N

        jPanel5.setBackground(new java.awt.Color(245, 255, 245));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("List Shared Files"));

        listSharedFile.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listSharedFile.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listSharedFile.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listSharedFileValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(listSharedFile);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
        );

        jPanel6.setBackground(new java.awt.Color(245, 255, 245));
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin file", javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel6.setText("File ID:");

        jLabel7.setText("File Name:");

        jLabel8.setText("Size:");

        lblFileName.setForeground(new java.awt.Color(51, 0, 204));

        lblFileId.setForeground(new java.awt.Color(51, 0, 204));

        lblFileSize.setForeground(new java.awt.Color(51, 0, 204));

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblFileId, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblFileName, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblFileSize, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(lblFileId))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(lblFileName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(lblFileSize))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBackground(new java.awt.Color(245, 255, 245));
        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Các client chia sẻ file", javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        listFileClient.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listFileClient.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listFileClientValueChanged(evt);
            }
        });
        jScrollPane4.setViewportView(listFileClient);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jMenu1.setText("File");

        mnuExit.setText("Exit");
        mnuExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuExitActionPerformed(evt);
            }
        });
        jMenu1.add(mnuExit);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        mnuConfig.setText("Configuration");
        mnuConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuConfigActionPerformed(evt);
            }
        });
        jMenu2.add(mnuConfig);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("Help");

        mnuAbout.setText("About");
        mnuAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuAboutActionPerformed(evt);
            }
        });
        jMenu3.add(mnuAbout);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void listClientsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listClientsValueChanged
        if(listClients.getSelectedIndex()>=0)
        {
            listOnline.clearSelection();
            listFileClient.clearSelection();
            String id=(String)listClients.getModel().getElementAt(listClients.getSelectedIndex());
            
            loadInfoClient(id);
        }
    }//GEN-LAST:event_listClientsValueChanged

    private void listOnlineValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listOnlineValueChanged
        if(listOnline.getSelectedIndex()>=0)
        {
            listClients.clearSelection();
            listFileClient.clearSelection();
            String id=(String)listOnline.getModel().getElementAt(listOnline.getSelectedIndex());
            
            loadInfoClient(id);
        }
    }//GEN-LAST:event_listOnlineValueChanged

    private void listFileClientValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listFileClientValueChanged
        if(listFileClient.getSelectedIndex()>=0)
        {
            listClients.clearSelection();
            listOnline.clearSelection();
            String id=(String)listFileClient.getModel().getElementAt(listFileClient.getSelectedIndex());
            
            loadInfoClient(id);
        }
    }//GEN-LAST:event_listFileClientValueChanged

    private void listSharedFileValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listSharedFileValueChanged
        if(listSharedFile.getSelectedIndex()>=0)
        {
            String id=arrInfoSharedFiles.get(listSharedFile.getSelectedIndex()).getFid();
            
            loadInfoFile(id);
        }
    }//GEN-LAST:event_listSharedFileValueChanged

    private void mnuExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuExitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_mnuExitActionPerformed

    private void mnuConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuConfigActionPerformed
        frmConfigDlg config=new frmConfigDlg(this, true);
        config.setVisible(true);
    }//GEN-LAST:event_mnuConfigActionPerformed

    private void mnuAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuAboutActionPerformed
        frmAbout about=new frmAbout(this, true);
        about.setVisible(true);
    }//GEN-LAST:event_mnuAboutActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try
                {
                    UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
                }catch(Exception e)
                {
                    e.printStackTrace();
                }
                new frmMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JLabel lblFileId;
    private javax.swing.JLabel lblFileName;
    private javax.swing.JLabel lblFileSize;
    private javax.swing.JLabel lblID;
    private javax.swing.JLabel lblIP;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblPort;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JList listClients;
    private javax.swing.JList listFileClient;
    private javax.swing.JList listOnline;
    private javax.swing.JList listSharedFile;
    private javax.swing.JMenuItem mnuAbout;
    private javax.swing.JMenuItem mnuConfig;
    private javax.swing.JMenuItem mnuExit;
    // End of variables declaration//GEN-END:variables
}
